package com.link2room.optimus.facade.impl;

import com.link2room.bumblebee.dto.param.base.PmsReservationOptionParamDto;
import com.link2room.bumblebee.dto.result.base.PmsReservationOptionDto;
import com.link2room.common.constant.BaseConstant;
import com.link2room.common.constant.DefaultValue;
import com.link2room.common.dto.result.base.HotelBaseInfoDto;
import com.link2room.common.dto.result.base.MemberSessionDto;
import com.link2room.common.dto.threadlocal.ApiThreadLocal;
import com.link2room.common.entity.BaseEntity;
import com.link2room.common.enums.BaseSysExceptionEnum;
import com.link2room.common.exception.SysException;
import com.link2room.common.jpa.condition.ConditionDetail;
import com.link2room.common.jpa.condition.L2RCondition;
import com.link2room.common.jpa.criteria.CriteriaUtil;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.common.mns.MNSUtil;
import com.link2room.common.service.ICommonService;
import com.link2room.common.util.*;

import com.link2room.enums.exception.OptimusSysExceptionEnum;
import com.link2room.ironhide.dto.param.base.RoomtypeBaseParamDto;
import com.link2room.ironhide.dto.param.inside.HotelBaseInfoInsideParamDto;
import com.link2room.ironhide.dto.param.inside.HotelMinPriceInsideParamDto;
import com.link2room.ironhide.dto.param.inside.L2RCommissionInsideParamDto;

import com.link2room.ironhide.dto.result.base.L2RCommissionDto;
import com.link2room.ironhide.dto.result.base.L2RRoomtypeDto;
import com.link2room.jetfire.constant.JetfireMnsConstant;
import com.link2room.jetfire.constant.ReservationConstant;
import com.link2room.jetfire.dto.param.base.ReservationParamDto;
import com.link2room.jetfire.dto.param.inside.ReservationNmsStaInsideParamDto;
import com.link2room.optimus.constant.OptimusMnsConstant;
import com.link2room.optimus.constant.OptimusTaskNameConstant;
import com.link2room.optimus.dto.param.base.MarketingBaseParamDto;
import com.link2room.optimus.dto.param.base.MarketingStockBaseParamDto;
import com.link2room.optimus.dto.param.inside.BookStockInsideParamDto;
import com.link2room.optimus.dto.param.manager.L2RRateplanHotelManagerParamDto;
import com.link2room.optimus.dto.param.manager.MarketingManagerParamDto;
import com.link2room.optimus.dto.param.manager.RateplanHotelManagerParamDto;
import com.link2room.optimus.dto.result.base.*;
import com.link2room.optimus.entity.*;
import com.link2room.optimus.exception.OptimusException;
import com.link2room.optimus.facade.IMarketingFacadeService;
import com.link2room.optimus.feign.bumblebee.PmsReservationOptionFeignService;
import com.link2room.optimus.feign.ironhide.CommissionFeignService;
import com.link2room.optimus.feign.ironhide.HotelBaseInfoFeignService;
import com.link2room.optimus.feign.ironhide.RoomtypeFeignService;
import com.link2room.optimus.feign.quintesson.TaobaoXrateplanFeignService;
import com.link2room.optimus.feign.rodimus.PointFeignService;
import com.link2room.optimus.feign.soundwave.PmsAvailFeignService;
import com.link2room.optimus.mapper.HotelMinPriceMapper;
import com.link2room.optimus.mapper.PriceStaticMapper;
import com.link2room.optimus.service.IMarketingService;
import com.link2room.optimus.util.MarketingUtil;
import com.link2room.optimus.util.PricePoolUtil;
import com.link2room.quintesson.dto.param.base.TaobaoXrateplanHotelBaseParamDto;
import com.link2room.rodimus.constant.MemberConstant;
import com.link2room.rodimus.dto.param.base.PointBaseParamDto;
import com.link2room.rodimus.dto.result.base.PointCheckDto;
import com.link2room.soundwave.dto.param.inside.PmsRoomAvailInsideParamDto;
import com.link2room.soundwave.dto.result.base.PmsRmtypeAvailDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;

/**
 * Created by sss on 2016/9/1.
 */
@Component("marketingFacadeService")
public class MarketingFacadeServiceImpl implements IMarketingFacadeService {
    @Resource
    private ICommonService commonService;
    @Resource
    private IMarketingService marketingService;
    @Autowired
    private PmsReservationOptionFeignService pmsReservationOptionFeignService;
    @Autowired
    private RoomtypeFeignService roomtypeFeignService;
    @Autowired
    private CommissionFeignService commissionFeignService;
    @Autowired
    private HotelBaseInfoFeignService hotelBaseInfoFeignService;
    @Autowired
    private PmsAvailFeignService pmsAvailFeignService;
    @Autowired
    private PointFeignService pointFeignService;
    @Autowired
    private TaobaoXrateplanFeignService taobaoXrateplanFeignService;

    @Resource
    private MNSUtil mnsUtil;



    /**
     * 保存活动（集团）
     * @param marketingManagerParamDto
     * @throws Exception
     */
    @Override
    public MarketingDto saveMarketing(MarketingManagerParamDto marketingManagerParamDto)throws Exception{
        MarketingDto marketingDto = marketingManagerParamDto.getMarketing();
        //可预订日期
        if(StringUtil.isBlank(marketingDto.getRsvStartDatetime())){
            marketingDto.setRsvStartDatetime(marketingDto.getStartDatetime());
        }
        if(StringUtil.isBlank(marketingDto.getRsvEndDatetime())){
            marketingDto.setRsvEndDatetime(marketingDto.getEndDatetime());
        }
        if("T".equals(marketingDto.getIsLong())){
            marketingDto.setEndDatetime("2099-12-31 00:00:00");
            marketingDto.setRsvEndDatetime("2099-12-31 00:00:00");
        }
        Integer generateDays=200;
        //Integer useDays=180;
        String generateDaysStr = SysoptionUtil.getSysOption(marketingDto.getLhotelGroupCode(),"MARKETING","generate_days");

        /*SysOptions querySysOptions=new SysOptions();
        querySysOptions.setLhotelGroupCode(marketingDto.getLhotelGroupCode());
        querySysOptions.setCategory("MARKETING");
        querySysOptions.setItem("generate_days");
        SysOptions sysOptions1=commonService.findOneEQ(SysOptions.class,querySysOptions);
        querySysOptions.setItem("use_days");*/
        //SysOptions sysOptions2=commonService.findOneEQ(SysOptions.class,querySysOptions);
        if(StringUtil.isNotBlank(generateDaysStr)){
            generateDays=Integer.parseInt(generateDaysStr);
        }
        /*if(sysOptions2!=null){
            useDays=Integer.parseInt(sysOptions2.getSetValue());
        }*/
        marketingManagerParamDto.setGenerateDays(generateDays);

        //计算出可预订跟不可预订日期列表
        marketingManagerParamDto =this.getMarketingDateList(marketingManagerParamDto);

        List<MarketingCampaignsExdate> marketingCampaignsExdates=new ArrayList<>();
        MarketingCampaignsExdate marketingCampaignsExdate=null;
        for(Date exdate: marketingManagerParamDto.getExdates()){
            marketingCampaignsExdate=new MarketingCampaignsExdate();
            marketingCampaignsExdate.setLhotelGroupCode(marketingManagerParamDto.getMarketing().getLhotelGroupCode());
            marketingCampaignsExdate.setMcCode(marketingManagerParamDto.getMarketing().getMcCode());
            marketingCampaignsExdate.setExdate(exdate);
            marketingCampaignsExdate.setWeekd(DateUtil.getDateWeek(exdate));
            marketingCampaignsExdates.add(marketingCampaignsExdate);
        }

        //活动主体
        MarketingCampaigns marketingCampaigns=ClassConverUtil.copyProperties(marketingDto, MarketingCampaigns.class);
        //活动星期
        List<MarketingCampaignsWeek> marketingCampaignsWeeks=ClassConverUtil.copyPropertiesList(marketingDto.getMarketingWeeks(),MarketingCampaignsWeek.class);
        //活动不可订规则
        List<MarketingCampaignsNorsv> marketingCampaignsNorsvs=null;
        if(marketingDto.getMarketingNorsvs()!=null&& marketingDto.getMarketingNorsvs().size()>0){
            marketingCampaignsNorsvs=ClassConverUtil.copyPropertiesList(marketingDto.getMarketingNorsvs(),MarketingCampaignsNorsv.class);
        }
        marketingService.saveMarketingGroupBase(marketingCampaigns,
                marketingCampaignsWeeks,marketingCampaignsNorsvs,marketingCampaignsExdates);
        MarketingDto marketing = ClassConverUtil.copyPropertiesToDto(marketingCampaigns, MarketingDto.class,false);
        marketing.setMarketingWeeks(ClassConverUtil.copyPropertiesList(marketingCampaignsWeeks,MarketingWeekDto.class));

        marketing.setMarketingNorsvs(ClassConverUtil.copyPropertiesList(marketingCampaignsNorsvs,MarketingNorsvDto.class));

        return marketing;
    }

    /**
     * 更新活动（集团）
     * @param marketingManagerParamDto
     * @throws Exception
     */
    @Override
    public void updateMarketing(MarketingManagerParamDto marketingManagerParamDto)throws Exception{
        MarketingDto marketingDto = marketingManagerParamDto.getMarketing();
        //可预订日期
        if(StringUtil.isBlank(marketingDto.getRsvStartDatetime())){
            marketingDto.setRsvStartDatetime(marketingDto.getStartDatetime());
        }
        if(StringUtil.isBlank(marketingDto.getRsvEndDatetime())){
            marketingDto.setRsvEndDatetime(marketingDto.getEndDatetime());
        }
        if("T".equals(marketingDto.getIsLong())){
            marketingDto.setEndDatetime("2099-12-31 00:00:00");
            marketingDto.setRsvEndDatetime("2099-12-31 00:00:00");
        }
        Integer generateDays=200;
        //Integer useDays=180;
        String generateDaysStr = SysoptionUtil.getSysOption(marketingDto.getLhotelGroupCode(),"MARKETING","generate_days");

        if(StringUtil.isNotBlank(generateDaysStr)){
            generateDays=Integer.parseInt(generateDaysStr);
        }
        marketingManagerParamDto.setGenerateDays(generateDays);
        List<MarketingCampaignsExdate> marketingCampaignsExdates=new ArrayList<>();
        //活动星期
        List<MarketingCampaignsWeek> marketingCampaignsWeeks=null;
        if(marketingDto.getMarketingWeeks()!=null&& marketingDto.getMarketingWeeks().size()>0){
            marketingCampaignsWeeks=ClassConverUtil.copyPropertiesList(marketingDto.getMarketingWeeks(),MarketingCampaignsWeek.class);
            marketingManagerParamDto =this.getMarketingDateList(marketingManagerParamDto);
            MarketingCampaignsExdate marketingCampaignsExdate=null;
            for(Date exdate: marketingManagerParamDto.getExdates()){
                marketingCampaignsExdate=new MarketingCampaignsExdate();
                marketingCampaignsExdate.setLhotelGroupCode(marketingManagerParamDto.getMarketing().getLhotelGroupCode());
                marketingCampaignsExdate.setMcCode(marketingManagerParamDto.getMarketing().getMcCode());
                marketingCampaignsExdate.setExdate(exdate);
                marketingCampaignsExdate.setWeekd(DateUtil.getDateWeek(exdate));
                marketingCampaignsExdates.add(marketingCampaignsExdate);
            }
        }

        //活动主体
        MarketingCampaigns marketingCampaigns=ClassConverUtil.copyProperties(marketingDto, MarketingCampaigns.class);

        //活动不可订规则
        List<MarketingCampaignsNorsv> marketingCampaignsNorsvs=null;
        if(marketingDto.getMarketingNorsvs()!=null&& marketingDto.getMarketingNorsvs().size()>0){
            marketingCampaignsNorsvs=ClassConverUtil.copyPropertiesList(marketingDto.getMarketingNorsvs(),MarketingCampaignsNorsv.class);
        }
        marketingService.updateMarketingGroupBase(marketingCampaigns,
                marketingCampaignsWeeks,marketingCampaignsNorsvs,marketingCampaignsExdates);
    }

    /**
     * 活动列表
     * @param marketingManagerParamDto
     * @return
     * @throws Exception
     */
    @Override
    public QueryResult<MarketingDto> listMarketings(MarketingManagerParamDto marketingManagerParamDto)throws Exception{
        String lhotelGroupCode=marketingManagerParamDto.getLhotelGroupCode();
        MarketingCampaigns queryMC=new MarketingCampaigns();
        queryMC.setLhotelGroupCode(lhotelGroupCode);
        QueryResult<MarketingCampaigns> mcResult = commonService.findAllEQ(MarketingCampaigns.class, queryMC,marketingManagerParamDto.getCurrentPage(),marketingManagerParamDto.getPageSize());
        return ClassConverUtil.copyQueryResultToDtoQueryResult(mcResult,MarketingDto.class,false);
    }

    /**
     * 房型报名活动列表
     * @param marketingManagerParamDto
     * @return
     * @throws Exception
     */
    @Override
    public QueryResult<MarketingDto> listRmtypeEnterMarketings(MarketingManagerParamDto marketingManagerParamDto)throws Exception{
        String lhotelGroupCode=marketingManagerParamDto.getLhotelGroupCode();
        String lhotelCode=marketingManagerParamDto.getLhotelCode();
        String rmtype=marketingManagerParamDto.getRmtype();
        String groupRmtype=marketingManagerParamDto.getGroupRmtype();
        MarketingCampaigns queryMC=new MarketingCampaigns();
        queryMC.setLhotelGroupCode(lhotelGroupCode);
        if(StringUtil.isNotBlank(marketingManagerParamDto.getIsHalt())){
            queryMC.setIsHalt(marketingManagerParamDto.getIsHalt());
        }
        QueryResult<MarketingCampaigns> mcResult = commonService.findAllEQ(MarketingCampaigns.class, queryMC,marketingManagerParamDto.getCurrentPage(),marketingManagerParamDto.getPageSize());
        if(StringUtil.isNotBlank(rmtype)&&StringUtil.isNotBlank(groupRmtype)){
            MarketingCampaignsDetail querymcd=new MarketingCampaignsDetail();
            querymcd.setLhotelGroupCode(lhotelGroupCode);
            querymcd.setLhotelCode(lhotelCode);
            querymcd.setRmtype(rmtype);
            QueryResult<MarketingCampaignsDetail> mcdResult=commonService.findAllEQ(MarketingCampaignsDetail.class,querymcd);
            MarketingCampaignsRmtype querymcr=new MarketingCampaignsRmtype();
            querymcr.setLhotelGroupCode(lhotelGroupCode);
            querymcr.setGroupRmtype(groupRmtype);
            querymcr.setIsHalt(DefaultValue.F);
            QueryResult<MarketingCampaignsRmtype> mcrResult=commonService.findAllEQ(MarketingCampaignsRmtype.class,querymcr);
            List<MarketingCampaigns> mcList=new ArrayList<>();
            if(mcResult.getResultlist()!=null){
                for(MarketingCampaigns mc:mcResult.getResultlist()){
                    mc.setMcName(this.getComposeMcName(mc));
                    if(mcrResult.getResultlist()!=null){
                        for(MarketingCampaignsRmtype mcr:mcrResult.getResultlist()){
                            if(mc.getMcCode().equals(mcr.getMcCode())){
                                mc.setIsHalt(DefaultValue.T);
                                mcList.add(mc);
                            }
                        }
                    }
                }
                for(MarketingCampaigns mc:mcList){
                    if(mcdResult.getResultlist()!=null){
                        for(MarketingCampaignsDetail mcd:mcdResult.getResultlist()){
                            if(mcd.getMcCode().equals(mc.getMcCode())){
                                mc.setIsHalt(mcd.getIsHalt());
                            }
                        }
                    }
                }
                mcResult.setResultlist(mcList);
                mcdResult.setTotalrecord(mcList.size());
            }
            return ClassConverUtil.copyQueryResultToDtoQueryResult(mcResult,MarketingDto.class,false);
        }else {
            throw new SysException(BaseSysExceptionEnum.INVALID_PARA);
        }
    }

    /**
     * 单个活动
     * @param marketingManagerParamDto
     * @return
     * @throws Exception
     */
    @Override
    public MarketingDto findMarketing(MarketingManagerParamDto marketingManagerParamDto)throws Exception{
        MarketingCampaigns mc = commonService.findOneById(MarketingCampaigns.class,marketingManagerParamDto.getId());
        MarketingCampaignsWeek queryMcw=new MarketingCampaignsWeek();
        queryMcw.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        queryMcw.setMcCode(mc.getMcCode());
        MarketingCampaignsNorsv queryMcn=new MarketingCampaignsNorsv();
        queryMcn.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        queryMcn.setMcCode(mc.getMcCode());
        QueryResult<MarketingCampaignsWeek> mcwResult = commonService.findAllEQ(MarketingCampaignsWeek.class, queryMcw);
        QueryResult<MarketingCampaignsNorsv> mcnResult = commonService.findAllEQ(MarketingCampaignsNorsv.class, queryMcn);
        MarketingDto marketing = ClassConverUtil.copyPropertiesToDto(mc, MarketingDto.class,false);
        if(mcwResult.getResultlist()!=null){
            marketing.setMarketingWeeks(ClassConverUtil.copyPropertiesList(mcwResult.getResultlist(),MarketingWeekDto.class));
        }
        if(mcnResult.getResultlist()!=null){
            marketing.setMarketingNorsvs(ClassConverUtil.copyPropertiesList(mcnResult.getResultlist(),MarketingNorsvDto.class));
        }
        return marketing;
    }

    /**
     * 单个活动所有信息
     * @param marketingManagerParamDto
     * @return
     * @throws Exception
     */
    @Override
    public MarketingAllDto findMarketingAll(MarketingManagerParamDto marketingManagerParamDto)throws Exception{
        MarketingAllDto marketingAll=new MarketingAllDto();
        MarketingCampaigns queryMc=new MarketingCampaigns();
        queryMc.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        queryMc.setMcCode(marketingManagerParamDto.getMcCode());
        MarketingCampaigns mc = commonService.findOneEQ(MarketingCampaigns.class,queryMc);
        MarketingCampaignsWeek queryMcw=new MarketingCampaignsWeek();
        queryMcw.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        queryMcw.setMcCode(mc.getMcCode());
        MarketingCampaignsNorsv queryMcn=new MarketingCampaignsNorsv();
        queryMcn.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        queryMcn.setMcCode(mc.getMcCode());
        QueryResult<MarketingCampaignsWeek> mcwResult = commonService.findAllEQ(MarketingCampaignsWeek.class, queryMcw);
        QueryResult<MarketingCampaignsNorsv> mcnResult = commonService.findAllEQ(MarketingCampaignsNorsv.class, queryMcn);
        MarketingDto marketing = ClassConverUtil.copyPropertiesToDto(mc, MarketingDto.class,false);
        if(mcwResult.getResultlist()!=null){
            marketing.setMarketingWeeks(ClassConverUtil.copyPropertiesList(mcwResult.getResultlist(),MarketingWeekDto.class));
        }
        if(mcnResult.getResultlist()!=null){
            marketing.setMarketingNorsvs(ClassConverUtil.copyPropertiesList(mcnResult.getResultlist(),MarketingNorsvDto.class));
        }

        //酒店列表
        QueryResult<MarketingHotelDto> marketingHotelResult = this.listMarketingHotels(marketingManagerParamDto);
        //渠道信息列表
        QueryResult<MarketingPbChannelDto> marketingPbChannelResult = this.listMarketingPbChannels(marketingManagerParamDto);
        //房型信息列表
        QueryResult<MarketingRmtypeDto> marketingRmtypeResult = this.listMarketingRmtypes(marketingManagerParamDto);
        marketingAll.setMarketing(marketing);
        marketingAll.setMarketingHotels(marketingHotelResult.getResultlist());
        marketingAll.setMarketingPbChannels(marketingPbChannelResult.getResultlist());
        marketingAll.setMarketingRmtypes(marketingRmtypeResult.getResultlist());
        return marketingAll;
    }

    /**
     * 检查活动代码
     * @param marketingManagerParamDto
     * @return
     * @throws Exception
     */
    @Override
    public void checkMcCode(MarketingManagerParamDto marketingManagerParamDto)throws Exception{
        MarketingCampaigns querymc=new MarketingCampaigns();
        querymc.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        querymc.setMcCode(marketingManagerParamDto.getMcCode());
        MarketingCampaigns mc = commonService.findOneEQ(MarketingCampaigns.class, querymc);
        if(mc!=null){
            throw new SysException(OptimusSysExceptionEnum.MC_CODE_EXIT);
        }
    }


    /**
     * 酒店报名活动列表
     * @param marketingManagerParamDto
     * @return
     * @throws Exception
     */
    @Override
    public QueryResult<MarketingDto> listHotelEnterMarketings(MarketingManagerParamDto marketingManagerParamDto)throws Exception{
        String lhotelGroupCode=marketingManagerParamDto.getLhotelGroupCode();
        String lhotelCode=marketingManagerParamDto.getLhotelCode();
        MarketingCampaigns queryMC=new MarketingCampaigns();
        queryMC.setLhotelGroupCode(lhotelGroupCode);
        if(StringUtil.isNotBlank(marketingManagerParamDto.getIsHalt())){
            queryMC.setIsHalt(marketingManagerParamDto.getIsHalt());
        }
        QueryResult<MarketingCampaigns> mcResult = commonService.findAllEQ(MarketingCampaigns.class, queryMC,marketingManagerParamDto.getCurrentPage(),marketingManagerParamDto.getPageSize());
        if(StringUtil.isNotBlank(lhotelCode)){
            MarketingCampaignsHotel querymch=new MarketingCampaignsHotel();
            querymch.setLhotelGroupCode(lhotelGroupCode);
            querymch.setLhotelCode(lhotelCode);
            QueryResult<MarketingCampaignsHotel> mchResult=commonService.findAllEQ(MarketingCampaignsHotel.class,querymch);

            if(mcResult.getResultlist()!=null){
                for(MarketingCampaigns mc:mcResult.getResultlist()){
                    mc.setMcName(this.getComposeMcName(mc));
                    mc.setIsHalt(DefaultValue.T);
                    if(mchResult.getResultlist()!=null){
                        for(MarketingCampaignsHotel mch:mchResult.getResultlist()){
                            if(mc.getMcCode().equals(mch.getMcCode())){
                                mc.setIsHalt(mch.getIsHalt());
                            }
                        }
                    }
                }
            }
            return ClassConverUtil.copyQueryResultToDtoQueryResult(mcResult,MarketingDto.class,false);
        }else {
            throw new SysException(BaseSysExceptionEnum.INVALID_PARA);
        }
    }

    private MarketingManagerParamDto getMarketingDateList(MarketingManagerParamDto marketingManagerParamDto){
        StringBuffer haltWeek=new StringBuffer();
        StringBuffer useWeek=new StringBuffer();
        for(MarketingWeekDto weeks: marketingManagerParamDto.getMarketing().getMarketingWeeks()){
            if("F".equals(weeks.getIsHalt())){
                useWeek.append(weeks.getWeekd());
            }else {
                haltWeek.append(weeks.getWeekd());
            }
        }
        Date rsvStartDate= marketingManagerParamDto.getMarketing().getRsvStartDate();
        Date rsvEndDate= marketingManagerParamDto.getMarketing().getRsvEndDate();
        if("T".equals(marketingManagerParamDto.getMarketing().getIsLong())&&DateUtil.dateNum(rsvStartDate,rsvEndDate)> marketingManagerParamDto.getGenerateDays()){
            rsvEndDate=DateUtil.addDays(rsvStartDate, marketingManagerParamDto.getGenerateDays()-1);
        }
        List<Date> haltWeekdates=DateUtil.getDates(haltWeek.toString(),rsvStartDate,rsvEndDate);
        List<Date> useWeekdates=DateUtil.getDates(useWeek.toString(),rsvStartDate,rsvEndDate);

        Set<Date> exdateSet=new HashSet<>();
        if(marketingManagerParamDto.getMarketing().getMarketingNorsvs()!=null&& marketingManagerParamDto.getMarketing().getMarketingNorsvs().size()>0){
            for(MarketingNorsvDto marketingNorsv: marketingManagerParamDto.getMarketing().getMarketingNorsvs()){
                //不可预订日期
                if(StringUtil.isNotBlank(marketingNorsv.getNoRsvStartDatetime())&&StringUtil.isNotBlank(marketingNorsv.getNoRsvEndDatetime())){
                    List<Date> exdates=DateUtil.getDates("01234567",marketingNorsv.getNoRsvStartDate(),marketingNorsv.getNoRsvEndDate());
                    for(Date exdate:exdates){
                        exdateSet.add(exdate);
                    }
                }
            }
        }

        if(haltWeekdates!=null&&haltWeekdates.size()>0){
            for(Date haltWeekdate:haltWeekdates){
                exdateSet.add(haltWeekdate);
            }
        }
        List<Date> exdates=new ArrayList<>();
        if(exdateSet!=null){
            Iterator<Date> exdateIterator = exdateSet.iterator();
            MarketingCampaignsExdate marketingCampaignsExdate=null;
            while (exdateIterator.hasNext()){
                exdates.add(exdateIterator.next());
            }
        }
        for(Date exdate:exdates){
            for(Date date:useWeekdates){
                if(exdate.getTime()==date.getTime()){
                    useWeekdates.remove(date);
                    break;
                }
            }
        }
        marketingManagerParamDto.setExdates(exdates);
        marketingManagerParamDto.setUsedates(useWeekdates);
        return marketingManagerParamDto;
    }

    @Override
    public List<MarketingHotelDto> saveMarketingHotels(MarketingManagerParamDto marketingManagerParamDto) throws Exception {
        //活动酒店
        List<MarketingCampaignsHotel> marketingCampaignsHotels=ClassConverUtil.copyPropertiesList(marketingManagerParamDto.getMarketingHotels(),MarketingCampaignsHotel.class);
        commonService.saveList(marketingCampaignsHotels);
        return ClassConverUtil.copyPropertiesListToDtoList(marketingCampaignsHotels,MarketingHotelDto.class,false);
    }

    @Override
    public List<MarketingRmtypeDto> saveMarketingRmtypes(MarketingManagerParamDto marketingManagerParamDto) throws Exception {
        List<MarketingRmtypeDto> marketingRmtypeDtos = marketingManagerParamDto.getMarketingDetail().getMarketingRmtypes();
        List<MarketingCampaignsRmtype> markketingRmtypeList = ClassConverUtil.copyPropertiesList(marketingRmtypeDtos, MarketingCampaignsRmtype.class);
        commonService.saveList(markketingRmtypeList);
        MarketingCampaigns querymc=new MarketingCampaigns();
        querymc.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        querymc.setMcCode(marketingManagerParamDto.getMcCode());
        MarketingCampaigns mc = commonService.findOneEQ(MarketingCampaigns.class, querymc);
        mc.setUseSetNum(marketingManagerParamDto.getMarketingDetail().getUseSetNum());
        mc.setUseRealAvail(marketingManagerParamDto.getMarketingDetail().getUseRealAvail());
        commonService.merge(mc);

        MarketingCampaignsHotel querymch=new MarketingCampaignsHotel();
        querymch.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        querymch.setMcCode(marketingManagerParamDto.getMcCode());
        List<MarketingCampaignsHotel> mchList=new ArrayList<>();
        QueryResult<MarketingCampaignsHotel> mchResult = commonService.findAllEQ(MarketingCampaignsHotel.class, querymch);
        if(mchResult.getResultlist()!=null&&mchResult.getResultlist().size()>0){
            mchList=mchResult.getResultlist();
        }
        MarketingBaseParamDto marketingParam=null;
        List<MarketingBaseParamDto> marketingBaseParamDtos=new ArrayList<>();
        for(MarketingCampaignsHotel mch : mchList){
            marketingParam=new MarketingBaseParamDto();
            marketingParam.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
            marketingParam.setLhotelCode(mch.getLhotelCode());
            marketingParam.setMarketingRmtypes(marketingRmtypeDtos);
            marketingParam.setMcCode(mc.getMcCode());
            marketingParam.setMcName(mc.getMcName());
            marketingParam.setMcNameEn(mc.getMcNameEn());
            marketingParam.setOptType(DefaultValue.POST);
            marketingBaseParamDtos.add(marketingParam);
        }
        BatchUtil.beginBatchTask(OptimusMnsConstant.QUEUE_MARKETINGDETAIL,
                OptimusTaskNameConstant.SAVE_MARKETING_DETAIL,
                marketingBaseParamDtos);
        return ClassConverUtil.copyPropertiesListToDtoList(markketingRmtypeList,MarketingRmtypeDto.class,false);
    }

    @Override
    public void updateMarketingRmtypes(MarketingManagerParamDto marketingManagerParamDto) throws Exception {
        List<MarketingRmtypeDto> marketingRmtypeDtos = marketingManagerParamDto.getMarketingDetail().getMarketingRmtypes();
        commonService.saveOrUpdateList(ClassConverUtil.copyPropertiesList(marketingRmtypeDtos,MarketingCampaignsRmtype.class));
        MarketingCampaigns querymc=new MarketingCampaigns();
        querymc.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        querymc.setMcCode(marketingManagerParamDto.getMcCode());
        MarketingCampaigns mc = commonService.findOneEQ(MarketingCampaigns.class, querymc);
        mc.setUseSetNum(marketingManagerParamDto.getMarketingDetail().getUseSetNum());
        mc.setUseRealAvail(marketingManagerParamDto.getMarketingDetail().getUseRealAvail());
        commonService.merge(mc);

        MarketingCampaignsHotel querymch=new MarketingCampaignsHotel();
        querymch.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        querymch.setMcCode(marketingManagerParamDto.getMcCode());
        List<MarketingCampaignsHotel> mchList=new ArrayList<>();
        QueryResult<MarketingCampaignsHotel> mchResult = commonService.findAllEQ(MarketingCampaignsHotel.class, querymch);
        if(mchResult.getResultlist()!=null&&mchResult.getResultlist().size()>0){
            mchList=mchResult.getResultlist();
        }
        MarketingBaseParamDto marketingParam=null;
        List<MarketingBaseParamDto> marketingBaseParamDtos=new ArrayList<>();
        for(MarketingCampaignsHotel mch : mchList){
            marketingParam=new MarketingBaseParamDto();
            marketingParam.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
            marketingParam.setLhotelCode(mch.getLhotelCode());
            marketingParam.setMarketingRmtypes(marketingRmtypeDtos);
            marketingParam.setMcCode(mc.getMcCode());
            marketingParam.setMcName(mc.getMcName());
            marketingParam.setMcNameEn(mc.getMcNameEn());
            marketingParam.setOptType(DefaultValue.PUT);
            marketingBaseParamDtos.add(marketingParam);
        }
        BatchUtil.beginBatchTask(OptimusMnsConstant.QUEUE_MARKETINGDETAIL,
                OptimusTaskNameConstant.UPDATE_MARKETING_DETAIL,
                marketingBaseParamDtos);
    }

    @Override
    public QueryResult<MarketingRmtypeDto> listMarketingRmtypes(MarketingManagerParamDto marketingManagerParamDto) throws Exception {
        /*MarketingCampaigns querymc=new MarketingCampaigns();
        querymc.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        querymc.setMcCode(marketingManagerParamDto.getMcCode());
        MarketingCampaigns mc = commonService.findOneEQ(MarketingCampaigns.class, querymc);*/
        MarketingCampaignsRmtype querymcr=new MarketingCampaignsRmtype();
        querymcr.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        querymcr.setMcCode(marketingManagerParamDto.getMcCode());
        QueryResult<MarketingCampaignsRmtype> mcrResult = commonService.findAllEQ(MarketingCampaignsRmtype.class, querymcr);
       /* MarketingDetailDto marketingDetailDto=new MarketingDetailDto();
        marketingDetailDto.setUseRealAvail(mc.getUseRealAvail());
        marketingDetailDto.setUseSetNum(mc.getUseSetNum());
        if(mcrResult.getResultlist()!=null)
        marketingDetailDto.setMarketingRmtypes(ClassConverUtil.copyPropertiesList(mcrResult.getResultlist(),MarketingRmtypeDto.class));
        return marketingDetailDto;*/
        return ClassConverUtil.copyQueryResultToDtoQueryResult(mcrResult,MarketingRmtypeDto.class,false);
    }

    /**
     * 保存活动渠道相关
     * @param marketingManagerParamDto
     * @throws Exception
     */
    @Override
    public List<MarketingPbChannelDto> saveOrUpdateMarketingPbChannels(MarketingManagerParamDto marketingManagerParamDto) throws Exception {
        MarketingCampaignsHotel querymch=new MarketingCampaignsHotel();
        querymch.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        querymch.setMcCode(marketingManagerParamDto.getMcCode());
        List<MarketingCampaignsHotel> mchList=new ArrayList<>();
        QueryResult<MarketingCampaignsHotel> mchResult = commonService.findAllEQ(MarketingCampaignsHotel.class, querymch);
        if(mchResult.getResultlist()!=null&&mchResult.getResultlist().size()>0){
            mchList=mchResult.getResultlist();
        }
        //活动渠道
        List<MarketingCampaignsChannel> marketingCampaignsChannels=new ArrayList<>();
        List<MarketingCampaignsPrice> marketingCampaignsPrices=new ArrayList<>();
        //价格计划按渠道分配给酒店
        for (MarketingPbChannelDto marketingChannel:marketingManagerParamDto.getMarketingPbChannels()){
            marketingCampaignsChannels.add(ClassConverUtil.copyProperties(marketingChannel,MarketingCampaignsChannel.class));
            if(marketingChannel.getMarketingPrices()!=null){
                marketingCampaignsPrices.addAll(ClassConverUtil.copyPropertiesList(marketingChannel.getMarketingPrices(),MarketingCampaignsPrice.class));
            }
        }
        marketingService.saveOrUpdateMarketingPbChannels(marketingCampaignsChannels, marketingCampaignsPrices );
        List<RateplanHotelManagerParamDto> rateplanHotelManagerParamDtos =new ArrayList<>();
        List<MarketingPbChannelDto> marketingPbChannelList = ClassConverUtil.copyPropertiesListToDtoList(marketingCampaignsChannels, MarketingPbChannelDto.class, false);
        for(MarketingCampaignsHotel mch:mchList){
            RateplanHotelManagerParamDto rateplanHotelManagerParamDto =new RateplanHotelManagerParamDto();
            rateplanHotelManagerParamDto.setLhotelCode(mch.getLhotelCode());
            rateplanHotelManagerParamDto.setMarketingHotel(ClassConverUtil.copyPropertiesToDto(mch,MarketingHotelDto.class,false));
            rateplanHotelManagerParamDto.setMarketingPbChannels(marketingPbChannelList);
            rateplanHotelManagerParamDtos.add(rateplanHotelManagerParamDto);
        }
        BatchUtil.beginBatchTask(OptimusMnsConstant.QUEUE_RATEPLANHOTEL,
                OptimusTaskNameConstant.SAVE_OR_UPDATE_RATEPLAN_HOTEL,
                rateplanHotelManagerParamDtos);
        List<MarketingPriceDto> marketingPriceList = ClassConverUtil.copyPropertiesListToDtoList(marketingCampaignsPrices, MarketingPriceDto.class, false);

        for(MarketingPbChannelDto marketingPbChannel:marketingPbChannelList){
            List<MarketingPriceDto> newMarketingPriceList=new ArrayList<>();
            for(MarketingPriceDto marketingPrice:marketingPriceList){
                if(marketingPrice.getMcCode().equals(marketingPbChannel.getMcCode())
                        &&marketingPrice.getPbChannel().equals(marketingPbChannel.getPbChannel())){
                    newMarketingPriceList.add(marketingPrice);
                }
            }
            marketingPbChannel.setMarketingPrices(newMarketingPriceList);
        }
        return marketingPbChannelList;
    }

    @Override
    public void saveOrUpdateRateplanHotel(RateplanHotelManagerParamDto rateplanHotelManagerParamDto)throws Exception{
        for (MarketingPbChannelDto marketingChannel: rateplanHotelManagerParamDto.getMarketingPbChannels()) {
            L2RRateplanHotelManagerParamDto l2RRateplanHotelManagerParamDto=ClassConverUtil.copyProperties(rateplanHotelManagerParamDto,L2RRateplanHotelManagerParamDto.class);
            l2RRateplanHotelManagerParamDto.setMarketingPbChannel(marketingChannel);
            switch (marketingChannel.getPbChannel()){
                case BaseConstant.PbChannelConstant.WECHAT:
                    this.saveOrUpdateL2rRateplanHotel(l2RRateplanHotelManagerParamDto);
                    continue;
                case BaseConstant.PbChannelConstant.WEB:
                    this.saveOrUpdateL2rRateplanHotel(l2RRateplanHotelManagerParamDto);
                    continue;
                case BaseConstant.PbChannelConstant.TAOBAO:
                    this.saveOrUpdateTaobaoRateplanHotel(l2RRateplanHotelManagerParamDto);
                    continue;
                default:
                    continue;
            }
        }
        BatchUtil.doBatchTaskDone(rateplanHotelManagerParamDto.getTaskMainId(),
                rateplanHotelManagerParamDto.getTaskId(),
                rateplanHotelManagerParamDto.getIsBatch());
    }

    private void saveOrUpdateTaobaoRateplanHotel(L2RRateplanHotelManagerParamDto l2RRateplanHotelManagerParamDto)throws Exception{
        TaobaoXrateplanHotelBaseParamDto taobaoXrateplanHotelBaseParamDto=new TaobaoXrateplanHotelBaseParamDto();
        MarketingPbChannelDto marketingChannel = l2RRateplanHotelManagerParamDto.getMarketingPbChannel();
        String taobaoRateplanHotelIsHalt=DefaultValue.F;
        if((l2RRateplanHotelManagerParamDto.getMarketingHotel()!=null&&
                l2RRateplanHotelManagerParamDto.getMarketingHotel().getIsHalt().equals(DefaultValue.T))
                ||marketingChannel.getIsHalt().equals(DefaultValue.T)){
            taobaoRateplanHotelIsHalt=DefaultValue.T;
        }
        taobaoXrateplanHotelBaseParamDto.setLhotelGroupCode(l2RRateplanHotelManagerParamDto.getLhotelGroupCode());
        taobaoXrateplanHotelBaseParamDto.setLhotelCode(l2RRateplanHotelManagerParamDto.getLhotelCode());
        taobaoXrateplanHotelBaseParamDto.setRpCode(marketingChannel.getRpCode());
        taobaoXrateplanHotelBaseParamDto.setHotelRpCode(MarketingUtil.getHotelRpCode(l2RRateplanHotelManagerParamDto.getLhotelCode(),marketingChannel.getRpCode()));
        taobaoXrateplanHotelBaseParamDto.setIsHalt(taobaoRateplanHotelIsHalt);
        taobaoXrateplanFeignService.updateTaobaoXrateplanHotel(taobaoXrateplanHotelBaseParamDto);
    }

    private void saveOrUpdateL2rRateplanHotel(L2RRateplanHotelManagerParamDto l2RRateplanHotelManagerParamDto)throws Exception{
        MarketingPbChannelDto marketingChannel = l2RRateplanHotelManagerParamDto.getMarketingPbChannel();
        L2RRateplanHotel queryLRH = new L2RRateplanHotel();
        queryLRH.setLhotelGroupCode(l2RRateplanHotelManagerParamDto.getLhotelGroupCode());
        queryLRH.setLhotelCode(l2RRateplanHotelManagerParamDto.getLhotelCode());
        queryLRH.setRpCode(marketingChannel.getRpCode());
        String l2rRateplanHotelIsHalt=DefaultValue.F;
        if((l2RRateplanHotelManagerParamDto.getMarketingHotel()!=null&&
                l2RRateplanHotelManagerParamDto.getMarketingHotel().getIsHalt().equals(DefaultValue.T))
                ||marketingChannel.getIsHalt().equals(DefaultValue.T)){
            l2rRateplanHotelIsHalt=DefaultValue.T;
        }
        L2RRateplanHotel l2RRateplanHotel = commonService.findOneEQ(L2RRateplanHotel.class, queryLRH);
        if (l2RRateplanHotel != null) {
            l2RRateplanHotel.setIsHalt(l2rRateplanHotelIsHalt);
            commonService.updateById(l2RRateplanHotel);
        } else {
            L2RRateplanHotel l2rRateplanHotel = new L2RRateplanHotel();
            l2rRateplanHotel.setLhotelGroupCode(l2RRateplanHotelManagerParamDto.getLhotelGroupCode());
            l2rRateplanHotel.setLhotelCode(l2RRateplanHotelManagerParamDto.getLhotelCode());
            l2rRateplanHotel.setRpCode(marketingChannel.getRpCode());
            l2rRateplanHotel.setHotelRpCode(MarketingUtil.getHotelRpCode(l2RRateplanHotelManagerParamDto.getLhotelCode(),marketingChannel.getRpCode()));
            l2rRateplanHotel.setIsHalt(l2rRateplanHotelIsHalt);
            commonService.saveOrUpdate(l2rRateplanHotel);
        }
    }

    @Override
    public QueryResult<MarketingPbChannelDto> listMarketingPbChannels(MarketingManagerParamDto marketingManagerParamDto) throws Exception {
        MarketingCampaignsChannel querymcc=new MarketingCampaignsChannel();
        querymcc.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        querymcc.setMcCode(marketingManagerParamDto.getMcCode());
        QueryResult<MarketingCampaignsChannel> mccResult = commonService.findAllEQ(MarketingCampaignsChannel.class, querymcc);
        QueryResult<MarketingPbChannelDto> marketingPbChannelResult = ClassConverUtil.copyQueryResultToDtoQueryResult(mccResult, MarketingPbChannelDto.class, false);
        List<MarketingPbChannelDto> marketingPbChannelList = marketingPbChannelResult.getResultlist();
        for(MarketingPbChannelDto marketingPbChannel:marketingPbChannelList){
            MarketingCampaignsPrice queryMcp=new MarketingCampaignsPrice();
            queryMcp.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
            queryMcp.setMcCode(marketingManagerParamDto.getMcCode());
            queryMcp.setPbChannel(marketingPbChannel.getPbChannel());
            QueryResult<MarketingCampaignsPrice> mcpResult = commonService.findAllEQ(MarketingCampaignsPrice.class, queryMcp);
            if (mcpResult.getResultlist()!=null){
                marketingPbChannel.setMarketingPrices(ClassConverUtil.copyPropertiesList(mcpResult.getResultlist(),MarketingPriceDto.class));
            }
        }
        return marketingPbChannelResult;
    }

    /**
     * 组装活动酒店级别内容
     * @param marketingBaseParamDto
     * @throws Exception
     */
    @Override
    public void composeMarketing(MarketingBaseParamDto marketingBaseParamDto)throws Exception{
        if (DefaultValue.POST.equals(marketingBaseParamDto.getOptType())) {
            this.saveMarketingDetail(marketingBaseParamDto);
        }else {
            this.updateMarketingDetail(marketingBaseParamDto);
        }
        BatchUtil.doBatchTaskDone(marketingBaseParamDto.getTaskMainId(),marketingBaseParamDto.getTaskId(),marketingBaseParamDto.getIsBatch());
    }

    /**
     * 保存活动详情
     * @param marketingBaseParamDto
     * @throws Exception
     */
    @Override
    public void saveMarketingDetail(MarketingBaseParamDto marketingBaseParamDto)throws Exception{
        RoomtypeBaseParamDto roomtypeBaseParamDto =new RoomtypeBaseParamDto();
        roomtypeBaseParamDto.setLhotelGroupCode(marketingBaseParamDto.getLhotelGroupCode());
        roomtypeBaseParamDto.setLhotelCode(marketingBaseParamDto.getLhotelCode());
        roomtypeBaseParamDto.setOptId(marketingBaseParamDto.getOptId());
        roomtypeBaseParamDto.setRmtype(marketingBaseParamDto.getRmtype());
        QueryResult<L2RRoomtypeDto> hotelRoomTypeResult = roomtypeFeignService.listRoomtype(roomtypeBaseParamDto.paramToMap()).getQueryResult();

        //活动房型
        List<MarketingRmtypeDto> marketingRmtypeDtos = marketingBaseParamDto.getMarketingRmtypes();
        if(marketingRmtypeDtos==null||marketingRmtypeDtos.size()<1){
            MarketingCampaignsRmtype querymcr=new MarketingCampaignsRmtype();
            querymcr.setLhotelGroupCode(marketingBaseParamDto.getLhotelGroupCode());
            querymcr.setMcCode(marketingBaseParamDto.getMcCode());
            querymcr.setGroupRmtype(marketingBaseParamDto.getRmtype());
            List<MarketingCampaignsRmtype> marketingRmtypes=commonService.findAllEQ(MarketingCampaignsRmtype.class, querymcr).getResultlist();
            if(marketingRmtypes !=null&&marketingRmtypes.size()>0){
                marketingRmtypeDtos=ClassConverUtil.copyPropertiesListToDtoList(marketingRmtypes,MarketingRmtypeDto.class,false);
            }
        }

        if(marketingRmtypeDtos!=null){
            MarketingCampaignsDetail querymcd=new MarketingCampaignsDetail();
            querymcd.setLhotelGroupCode(marketingBaseParamDto.getLhotelGroupCode());
            querymcd.setLhotelCode(marketingBaseParamDto.getLhotelCode());
            querymcd.setMcCode(marketingBaseParamDto.getMcCode());
            QueryResult<MarketingCampaignsDetail> mcdResult = commonService.findAllEQ(MarketingCampaignsDetail.class, querymcd);

            if(mcdResult.getResultlist()!=null&&mcdResult.getResultlist().size()>0){
                Iterator<MarketingRmtypeDto> mcrIterator = marketingRmtypeDtos.iterator();
                while (mcrIterator.hasNext()){
                    MarketingRmtypeDto mcr = mcrIterator.next();
                    for(MarketingCampaignsDetail mcd:mcdResult.getResultlist()){
                        if(mcd.getRmtype().equals(mcd.getLhotelCode()+DefaultValue.MARK+mcr.getGroupRmtype())){
                            mcrIterator.remove();
                        }
                    }
                }
            }

            MarketingCampaignsDetail marketingCampaignsDetail=null;
            List<MarketingCampaignsDetail> marketingCampaignsDetails=new ArrayList<>();
            for(MarketingRmtypeDto marketingRmtype:marketingRmtypeDtos){
                if(hotelRoomTypeResult.getResultlist()!=null){
                    for(L2RRoomtypeDto roomtype:hotelRoomTypeResult.getResultlist()){
                        if(CommonUtil.getHotelRmtype(marketingBaseParamDto.getLhotelCode(),marketingRmtype.getGroupRmtype()).equals(roomtype.getRmtype())){
                            String mcdCode=roomtype.getRmtype()+DefaultValue.MARK+marketingBaseParamDto.getMcCode();
                            marketingCampaignsDetail=new MarketingCampaignsDetail();
                            marketingCampaignsDetail.setLhotelGroupCode(marketingBaseParamDto.getLhotelGroupCode());
                            marketingCampaignsDetail.setLhotelCode(marketingBaseParamDto.getLhotelCode());
                            marketingCampaignsDetail.setMcCode(marketingBaseParamDto.getMcCode());
                            marketingCampaignsDetail.setMcdCode(mcdCode);
                            marketingCampaignsDetail.setMcdName(roomtype.getName()+"("+ marketingBaseParamDto.getMcName()+")");
                            marketingCampaignsDetail.setMcdNameEn(roomtype.getNameEn()+"("+ marketingBaseParamDto.getMcNameEn()+")");
                            marketingCampaignsDetail.setRmtype(roomtype.getRmtype());
                            marketingCampaignsDetail.setRmtypeName(roomtype.getName());
                            marketingCampaignsDetail.setRmtypeNameEn(roomtype.getNameEn());
                            marketingCampaignsDetail.setIsHalt(DefaultValue.F);
                            marketingCampaignsDetail.setSetNum(marketingRmtype.getSetNum());
                            marketingCampaignsDetails.add(marketingCampaignsDetail);
                        }
                    }
                }
            }
            commonService.saveList(marketingCampaignsDetails);
        }
    }

    /**
     * 更新活动详情
     * @param marketingBaseParamDto
     * @throws Exception
     */
    @Override
    public void updateMarketingDetail(MarketingBaseParamDto marketingBaseParamDto)throws Exception{
        RoomtypeBaseParamDto roomtypeBaseParamDto =new RoomtypeBaseParamDto();
        roomtypeBaseParamDto.setLhotelGroupCode(marketingBaseParamDto.getLhotelGroupCode());
        roomtypeBaseParamDto.setLhotelCode(marketingBaseParamDto.getLhotelCode());
        roomtypeBaseParamDto.setOptId(marketingBaseParamDto.getOptId());
        roomtypeBaseParamDto.setRmtype(marketingBaseParamDto.getRmtype());
        QueryResult<L2RRoomtypeDto> hotelRoomTypeResult = roomtypeFeignService.listRoomtype(roomtypeBaseParamDto.paramToMap()).getQueryResult();
        //活动房型
        List<MarketingRmtypeDto> marketingRmtypeDtos = marketingBaseParamDto.getMarketingRmtypes();
        if(marketingRmtypeDtos==null||marketingRmtypeDtos.size()<1){
            MarketingCampaignsRmtype querymcr=new MarketingCampaignsRmtype();
            querymcr.setLhotelGroupCode(marketingBaseParamDto.getLhotelGroupCode());
            querymcr.setMcCode(marketingBaseParamDto.getMcCode());
            querymcr.setGroupRmtype(marketingBaseParamDto.getGroupRmtype());
            List<MarketingCampaignsRmtype> marketingRmtypes=commonService.findAllEQ(MarketingCampaignsRmtype.class, querymcr).getResultlist();
            if(marketingRmtypes !=null&&marketingRmtypes.size()>0){
                marketingRmtypeDtos=ClassConverUtil.copyPropertiesListToDtoList(marketingRmtypes,MarketingRmtypeDto.class,false);
            }
        }

        if(marketingRmtypeDtos!=null){
            MarketingCampaignsDetail marketingCampaignsDetail=null;
            List<MarketingCampaignsDetail> marketingCampaignsDetails=new ArrayList<>();
            MarketingCampaignsDetail queryMcd=new MarketingCampaignsDetail();
            queryMcd.setLhotelGroupCode(marketingBaseParamDto.getLhotelGroupCode());
            queryMcd.setLhotelCode(marketingBaseParamDto.getLhotelCode());
            queryMcd.setMcCode(marketingBaseParamDto.getMcCode());
            QueryResult<MarketingCampaignsDetail> mcd = commonService.findAllEQ(MarketingCampaignsDetail.class, queryMcd);
            List<MarketingCampaignsDetail> mcdList = mcd.getResultlist();

            Iterator<L2RRoomtypeDto> iterator=null;

            if(hotelRoomTypeResult.getResultlist()!=null){
                iterator = hotelRoomTypeResult.getResultlist().iterator();
            }
            if(iterator!=null){
                while (iterator.hasNext()){
                    L2RRoomtypeDto l2RRoomtypeDto = iterator.next();
                    if(mcdList!=null){
                        for(MarketingCampaignsDetail mcDetail:mcdList) {
                            if(l2RRoomtypeDto.getRmtype().equals(mcDetail.getRmtype())){
                                iterator.remove();
                            }
                        }
                    }
                }
            }
            if(hotelRoomTypeResult.getResultlist()!=null){
                Iterator<L2RRoomtypeDto> newIterator = hotelRoomTypeResult.getResultlist().iterator();
                while (newIterator.hasNext()){
                    L2RRoomtypeDto l2RRoomtypeDto = newIterator.next();
                    String mcdCode=l2RRoomtypeDto.getRmtype()+DefaultValue.MARK+marketingBaseParamDto.getMcCode();
                    marketingCampaignsDetail=new MarketingCampaignsDetail();
                    marketingCampaignsDetail.setLhotelGroupCode(marketingBaseParamDto.getLhotelGroupCode());
                    marketingCampaignsDetail.setLhotelCode(marketingBaseParamDto.getLhotelCode());
                    marketingCampaignsDetail.setMcCode(marketingBaseParamDto.getMcCode());
                    marketingCampaignsDetail.setMcdCode(mcdCode);
                    marketingCampaignsDetail.setMcdName(l2RRoomtypeDto.getName()+"("+ marketingBaseParamDto.getMcName()+")");
                    marketingCampaignsDetail.setMcdNameEn(l2RRoomtypeDto.getNameEn()+"("+ marketingBaseParamDto.getMcNameEn()+")");
                    marketingCampaignsDetail.setRmtype(l2RRoomtypeDto.getRmtype());
                    marketingCampaignsDetail.setRmtypeName(l2RRoomtypeDto.getName());
                    marketingCampaignsDetail.setRmtypeNameEn(l2RRoomtypeDto.getNameEn());
                    marketingCampaignsDetails.add(marketingCampaignsDetail);
                }
            }
            if(mcdList!=null){
                for(MarketingCampaignsDetail mcDetail:mcdList) {
                    marketingCampaignsDetails.add(mcDetail);
                }
            }
            for(MarketingRmtypeDto marketingRmtype:marketingRmtypeDtos){
                for(MarketingCampaignsDetail mcDetail:marketingCampaignsDetails){
                    if(CommonUtil.getHotelRmtype(marketingBaseParamDto.getLhotelCode(),marketingRmtype.getGroupRmtype()).equals(mcDetail.getRmtype())) {
                        mcDetail.setMcdName(mcDetail.getRmtypeName()+"("+ marketingBaseParamDto.getMcName()+")");
                        mcDetail.setSetNum(marketingRmtype.getSetNum());
                        mcDetail.setIsHalt(marketingRmtype.getIsHalt());
                        if(StringUtil.isNotBlank(marketingBaseParamDto.getRmtypeIsHalt())){
                            mcDetail.setIsHalt(marketingBaseParamDto.getRmtypeIsHalt());
                        }
                    }
                }
            }
            commonService.saveOrUpdateList(marketingCampaignsDetails);
        }
    }

    @Override
    public void saveOrUpdateRmtypeEnterMarketingDetail(MarketingManagerParamDto marketingManagerParamDto)throws Exception{
        MarketingBaseParamDto marketingBaseParamDto=null;
        List<MarketingBaseParamDto> marketingBaseParamDtos=new ArrayList<>();
        for(MarketingDto mc:marketingManagerParamDto.getMarketings()){
            marketingBaseParamDto=new MarketingBaseParamDto();
            marketingBaseParamDto.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
            marketingBaseParamDto.setLhotelCode(marketingManagerParamDto.getLhotelCode());
            marketingBaseParamDto.setMcCode(mc.getMcCode());
            marketingBaseParamDto.setMcName(mc.getMcName());
            marketingBaseParamDto.setMcNameEn(mc.getMcNameEn());
            marketingBaseParamDto.setRmtypeIsHalt(mc.getIsHalt());
            marketingBaseParamDto.setRmtype(marketingManagerParamDto.getRmtype());
            marketingBaseParamDto.setGroupRmtype(marketingManagerParamDto.getGroupRmtype());
            marketingBaseParamDto.setOptType(DefaultValue.PUT);
            marketingBaseParamDtos.add(marketingBaseParamDto);
        }
        BatchUtil.beginBatchTask(OptimusMnsConstant.QUEUE_MARKETINGDETAIL,
                OptimusTaskNameConstant.SAVE_MARKETING_DETAIL,
                marketingBaseParamDtos);
    }

    @Override
    public void saveOrUpdateHotelEnterMarketingDetail(MarketingManagerParamDto marketingManagerParamDto)throws Exception{
        MarketingCampaignsHotel queryMch=new MarketingCampaignsHotel();
        queryMch.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        queryMch.setLhotelCode(marketingManagerParamDto.getLhotelCode());
        QueryResult<MarketingCampaignsHotel> mchResult = commonService.findAllEQ(MarketingCampaignsHotel.class, queryMch);
        List<MarketingCampaignsHotel> mchList = mchResult.getResultlist();
        MarketingHotelDto mHotelDto;
        MarketingManagerParamDto mManagerParamDto;
        List<MarketingManagerParamDto> marketingManagerParamList=new ArrayList<>();
        for(MarketingDto mc:marketingManagerParamDto.getMarketings()){
            mHotelDto=new MarketingHotelDto();
            mHotelDto.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
            mHotelDto.setLhotelCode(marketingManagerParamDto.getLhotelCode());
            mHotelDto.setIsHalt(mc.getIsHalt());
            mHotelDto.setIsNew(DefaultValue.T);
            mHotelDto.setMcCode(mc.getMcCode());
            mHotelDto.setName(HotelUtil.getRedisHotelName(marketingManagerParamDto.getLhotelCode()));
            mHotelDto.setNameEn(HotelUtil.getRedisHotelNameEn(marketingManagerParamDto.getLhotelCode()));
            if(mchList!=null){
                for (MarketingCampaignsHotel mch: mchList) {
                    if(mch.getMcCode().equals(mc.getMcCode())){
                        mHotelDto.setId(mch.getId());
                        mHotelDto.setIsNew(DefaultValue.F);
                    }
                }
            }
            List<MarketingHotelDto> mHotels=new ArrayList<>();
            mHotels.add(mHotelDto);
            mManagerParamDto=new MarketingManagerParamDto();
            mManagerParamDto.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
            mManagerParamDto.setLhotelCode(marketingManagerParamDto.getLhotelCode());
            mManagerParamDto.setMcCode(mc.getMcCode());
            mManagerParamDto.setMarketingHotels(mHotels);
            marketingManagerParamList.add(mManagerParamDto);
        }
        BatchUtil.beginBatchTask(OptimusMnsConstant.QUEUE_MARKETING_HOTEL,
                OptimusTaskNameConstant.SAVE_OR_UPDATE_MARKETING_HOTEL,
                marketingManagerParamList);
    }

    /**
     * 获得酒店最低价
     * @param hotelMinPriceInsideParamDto
     * @return
     * @throws Exception
     */
    @Override
    public QueryResult<HotelMinPriceDto> getHoteMinPrice(HotelMinPriceInsideParamDto hotelMinPriceInsideParamDto) throws Exception {
        QueryResult<HotelMinPriceMapper> hotelMinPriceMapperResult = marketingService.getHotelMinPrice(hotelMinPriceInsideParamDto.getLhotelGroupCode(), hotelMinPriceInsideParamDto.getLhotelCode(),
                hotelMinPriceInsideParamDto.getStartDatetime(), hotelMinPriceInsideParamDto.getEndDatetime(),hotelMinPriceInsideParamDto.getPbChannel() );
        QueryResult<HotelMinPriceDto> hotelMinPriceDtoResult=new QueryResult<>();
        List<HotelMinPriceDto> hotelMinPriceDtoList=new ArrayList<>();
        if(hotelMinPriceMapperResult.getResultlist()!=null&&hotelMinPriceMapperResult.getResultlist().size()>0){
            HotelMinPriceDto hotelMinPrice;
            for(HotelMinPriceMapper hotelMinPriceMapper:hotelMinPriceMapperResult.getResultlist()){
                hotelMinPrice=ClassConverUtil.copyPropertiesToDto(hotelMinPriceMapper,HotelMinPriceDto.class, false);
                hotelMinPrice.setMinPrice( PricePoolUtil.getPriceResult(hotelMinPriceMapper.getMinPrice(),hotelMinPriceMapper.getCarryType(),null,null));
                hotelMinPriceDtoList.add(hotelMinPrice);
            }
        }
        hotelMinPriceDtoResult.setResultlist(hotelMinPriceDtoList);
        hotelMinPriceDtoResult.setTotalrecord(hotelMinPriceMapperResult.getTotalrecord());
        return hotelMinPriceDtoResult;
    }

    /**
     * 获取产品明细列表
     * @param marketingManagerParamDto
     * @return
     * @throws Exception
     */
    @Override
    public QueryResult<MarketingDetailDto> listMarketingDetails(MarketingManagerParamDto marketingManagerParamDto)throws Exception{
        MarketingCampaignsDetail queryMcd=new MarketingCampaignsDetail();
        queryMcd.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        queryMcd.setLhotelCode(marketingManagerParamDto.getLhotelCode());
        queryMcd.setMcCode(marketingManagerParamDto.getMcCode());
        QueryResult<MarketingCampaignsDetail> marketingCampaignsDetailQueryResult=commonService.findAllEQ(MarketingCampaignsDetail.class,queryMcd, marketingManagerParamDto.getCurrentPage(), marketingManagerParamDto.getPageSize());
        return ClassConverUtil.copyQueryResultToDtoQueryResult(marketingCampaignsDetailQueryResult,MarketingDetailDto.class,false);
    }

    /**
     * 获得产品明细
     * @param bookStockInsideParamDto
     * @return
     * @throws Exception
     */
    @Override
    public BookStockDto getMarketingDetail(BookStockInsideParamDto bookStockInsideParamDto)throws Exception{
        String memberLevel= MemberConstant.MEMBER_LEVEL.L0;
        MemberSessionDto memberSession=null;
        if(StringUtil.isNotBlank(bookStockInsideParamDto.getTicket())){
            memberSession = ApiThreadLocal.getMemberSessionThreadLocal();
            memberLevel=memberSession.getMemberLevel();
        }
        //查询产品
        MarketingCampaignsDetail querymcd=new MarketingCampaignsDetail();
        querymcd.setLhotelGroupCode(bookStockInsideParamDto.getLhotelGroupCode());
        querymcd.setLhotelCode(bookStockInsideParamDto.getLhotelCode());
        querymcd.setMcdCode(bookStockInsideParamDto.getMcdCode());
        MarketingCampaignsDetail mcd=commonService.findOneEQ(MarketingCampaignsDetail.class,querymcd);
        MarketingCampaignsChannel querymcc=new MarketingCampaignsChannel();
        querymcc.setLhotelGroupCode(bookStockInsideParamDto.getLhotelGroupCode());
        querymcc.setMcCode(mcd.getMcCode());
        querymcc.setPbChannel(bookStockInsideParamDto.getPbChannel());
        MarketingCampaignsChannel mcc = commonService.findOneEQ(MarketingCampaignsChannel.class, querymcc);
        MarketingCampaigns querymc=new MarketingCampaigns();
        querymc.setLhotelGroupCode(bookStockInsideParamDto.getLhotelGroupCode());
        querymc.setMcCode(mcd.getMcCode());
        MarketingCampaigns mc = commonService.findOneEQ(MarketingCampaigns.class, querymc);
        //查询价格池
        MarketingCampaignsPrice querymcp=new MarketingCampaignsPrice();
        querymcp.setLhotelGroupCode(mcd.getLhotelGroupCode());
        querymcp.setMemberLevel(memberLevel);
        querymcp.setMcCode(mcd.getMcCode());
        querymcp.setPbChannel(bookStockInsideParamDto.getPbChannel());
        MarketingCampaignsPrice mcp = commonService.findOneEQ(MarketingCampaignsPrice.class, querymcp);
        PricePool querypp=new PricePool();
        querypp.setLhotelGroupCode(mcd.getLhotelGroupCode());
        querypp.setPoolCode(mcp.getPoolCode());
        PricePool pp = commonService.findOneEQ(PricePool.class, querypp);

        String pointRule=null;
        String resType;
        String pmsRatecode;
        BookStockDto bookStockDto=new BookStockDto();
        if(BaseConstant.PbChannelConstant.TAOBAO.equals(bookStockInsideParamDto.getPbChannel())){
            TaobaoXrateplan querytrp=new TaobaoXrateplan();
            querytrp.setLhotelGroupCode(bookStockInsideParamDto.getLhotelGroupCode());
            querytrp.setRpCode(mcc.getRpCode());
            TaobaoXrateplan trp = commonService.findOneEQ(TaobaoXrateplan.class, querytrp);
            bookStockDto.setTaobaoXrateplanDto(ClassConverUtil.copyPropertiesToDto(trp,TaobaoXrateplanDto.class, false));
            resType=trp.getResType();
            pmsRatecode=trp.getPmsRatecode();
        }else {
            L2RRateplan queryrp=new L2RRateplan();
            queryrp.setLhotelGroupCode(bookStockInsideParamDto.getLhotelGroupCode());
            queryrp.setRpCode(mcc.getRpCode());
            L2RRateplan rp = commonService.findOneEQ(L2RRateplan.class, queryrp);
            bookStockDto.setL2RRateplan(ClassConverUtil.copyPropertiesToDto(rp,L2RRateplanDto.class, false));
            resType=rp.getResType();
            pmsRatecode=rp.getPmsRatecode();
            pointRule=rp.getPointRule();
        }

        //查询房型基础价
        QueryResult<PriceStaticMapper> rmPriceResult = marketingService.getRmtypeStaticPrice(mcd.getLhotelGroupCode(), mcd.getLhotelCode(),mc.getPriceCode(),  mcd.getRmtype(),
                bookStockInsideParamDto.getCheckInDatetime(), bookStockInsideParamDto.getCheckOutDatetime());
        L2RCommissionInsideParamDto l2RCommissionInsideParamDto=new L2RCommissionInsideParamDto();
        l2RCommissionInsideParamDto.setPbChannel(bookStockInsideParamDto.getPbChannel());
        l2RCommissionInsideParamDto.setResType(resType);
        L2RCommissionDto commission = commissionFeignService.commission(l2RCommissionInsideParamDto.paramToMap()).getResultInfo();

        PmsReservationOptionParamDto pmsReservationOptionParamDto=new PmsReservationOptionParamDto();
        pmsReservationOptionParamDto.setPbChannel(mcc.getPbChannel());
        pmsReservationOptionParamDto.setResType(resType);
        PmsReservationOptionDto pmsReservationOptionDto= pmsReservationOptionFeignService.getPmsReservationOption(pmsReservationOptionParamDto.paramToMap()).getResultInfo();
        PmsRoomAvailInsideParamDto roomAvailParamDto=new PmsRoomAvailInsideParamDto();
        roomAvailParamDto.setLhotelGroupCode(mcd.getLhotelGroupCode());
        roomAvailParamDto.setLhotelCode(mcd.getLhotelCode());
        roomAvailParamDto.setL2RRmtypes(mcd.getRmtype());
        roomAvailParamDto.setArrtime(bookStockInsideParamDto.getCheckInDatetime());
        roomAvailParamDto.setDeptime(bookStockInsideParamDto.getCheckOutDatetime());
        roomAvailParamDto.setOptId(bookStockInsideParamDto.getOptId());
        roomAvailParamDto.setPmsRatecode(pmsRatecode);
        roomAvailParamDto.setSalesChannel(pmsReservationOptionDto.getSalesChannel());

        QueryResult<PmsRmtypeAvailDto> roomAvailResult = pmsAvailFeignService.getRoomAvailDirect(roomAvailParamDto.paramToMap()).getQueryResult();
        List<PmsRmtypeAvailDto> roomAvailList = roomAvailResult.getResultlist();
        L2RCondition stockConfition=new L2RCondition();
        stockConfition.setAndConditions(new ConditionDetail[]{
                new ConditionDetail(BaseEntity.BaseEntity_.lhotelGroupCode.toString(), CriteriaUtil.Operator.EQ,mcd.getLhotelGroupCode()),
                new ConditionDetail(BaseEntity.BaseEntity_.lhotelCode.toString(), CriteriaUtil.Operator.EQ,mcd.getLhotelCode()),
                new ConditionDetail(MarketingCampaignsStock.MarketingCampaignsStock_.mcdCode.toString(), CriteriaUtil.Operator.EQ,mcd.getMcdCode()),
                new ConditionDetail(MarketingCampaignsStock.MarketingCampaignsStock_.rsvDate.toString(), CriteriaUtil.Operator.GTE, bookStockInsideParamDto.getCheckInDate()),
                new ConditionDetail(MarketingCampaignsStock.MarketingCampaignsStock_.rsvDate.toString(), CriteriaUtil.Operator.LT, bookStockInsideParamDto.getCheckOutDate())
        });
        QueryResult<MarketingCampaignsStock> marketingStockResult = commonService.findAllByCondition(MarketingCampaignsStock.class, stockConfition);
        List<MarketingCampaignsStock> marketingStockList = marketingStockResult.getResultlist();
        QueryResult<MarketingCampaignsStockSold> marketingStockSoldResult = commonService.findAllByCondition(MarketingCampaignsStockSold.class, stockConfition);
        List<MarketingCampaignsStockSold> marketingStockSoldList = marketingStockSoldResult.getResultlist();


        boolean isBookableFlag=true;
        boolean isFullFlag=true;
        Integer minSaleNum=9999;
        HashMap<String,MarketingCampaignsStock> mcsMap=new HashMap<>();
        HashMap<String,MarketingCampaignsStockSold> mcsdMap=new HashMap<>();

        if(marketingStockList!=null){
            for(MarketingCampaignsStock marketingStock:marketingStockList){
                mcsMap.put(DateUtil.format(marketingStock.getRsvDate(),DateUtil.webFormat),marketingStock);
                if(marketingStock.getIsClosed().equals(DefaultValue.T)){
                    isBookableFlag=false;
                }
            }
        }
        if(marketingStockSoldList!=null){
            for(MarketingCampaignsStockSold marketingStockSold:marketingStockSoldList){
                mcsdMap.put(DateUtil.format(marketingStockSold.getRsvDate(),DateUtil.webFormat),marketingStockSold);
            }
        }
        Map<String,L2REverydayStockDto> stockMap=new HashMap<>();
        if(roomAvailList!=null){
            for (PmsRmtypeAvailDto roomAvail:roomAvailList) {
                String rsvDate = DateUtil.format(roomAvail.getRsvDate(), DateUtil.webFormat);
                MarketingCampaignsStock mcs = mcsMap.get(rsvDate);
                MarketingCampaignsStockSold mcsd = mcsdMap.get(rsvDate);
                minSaleNum = marketingService.getMinSaleNum(mc.getUseRealAvail(), mc.getUseSetNum(), minSaleNum, mcd.getSetNum(), mcs, mcsd, roomAvail);
                Integer saleNum = marketingService.getSaleNum(mc.getUseRealAvail(), mc.getUseSetNum(), mcd.getSetNum(), mcs, mcsd, roomAvail);

                L2REverydayStockDto l2REverydayStockDto = new L2REverydayStockDto();
                l2REverydayStockDto.setSaleNum(saleNum);
                String isClosed = DefaultValue.F;
                if (mcsMap.get(rsvDate) != null) {
                    isClosed = mcsMap.get(rsvDate).getIsClosed();
                }
                l2REverydayStockDto.setIsClosed(isClosed);
                stockMap.put(rsvDate, l2REverydayStockDto);
            }
        }


        BigDecimal totalPriceSale=new BigDecimal(0);
        BigDecimal totalPriceCost=new BigDecimal(0);
        BigDecimal totalPricePms=new BigDecimal(0);
        List<L2REverydayPriceAndStockDto> l2REverydayPriceAndStockDtos=new ArrayList<>();
        for(PriceStaticMapper rmPrice:rmPriceResult.getResultlist()){
            if(mc.getPriceCode().equals(rmPrice.getPriceCode())){
                L2REverydayPriceDto l2reverydayPrice=new L2REverydayPriceDto();
                BigDecimal costPrice= PricePoolUtil.getPriceResult(rmPrice.getPrice(),pp.getCarryType(),pp.getMultiplyValueCost(),pp.getAddValueCost());
                BigDecimal currentPrice= PricePoolUtil.getPriceResult(rmPrice.getPrice(),pp.getCarryType(),pp.getMultiplyValueSale(),pp.getAddValueSale());
                //TODO 暂时下发PMS价格不变
                BigDecimal pmsPrice= costPrice;

                totalPriceSale=totalPriceSale.add(currentPrice.multiply(new BigDecimal(bookStockInsideParamDto.getRmNum())));
                totalPriceCost=totalPriceCost.add(costPrice.multiply(new BigDecimal(bookStockInsideParamDto.getRmNum())));
                totalPricePms=totalPricePms.add(pmsPrice.multiply(new BigDecimal(bookStockInsideParamDto.getRmNum())));
                l2reverydayPrice.setRsvDate(rmPrice.getDate());
                l2reverydayPrice.setBasePrice(rmPrice.getPrice());
                l2reverydayPrice.setCurrentPrice(currentPrice);
                l2reverydayPrice.setCostPrice(costPrice);
                l2reverydayPrice.setPmsPrice(pmsPrice);
                l2reverydayPrice.datetimeToString();

                L2REverydayPriceAndStockDto l2REverydayPriceAndStockDto=new L2REverydayPriceAndStockDto();
                l2REverydayPriceAndStockDto.setL2REverydayPriceDto(l2reverydayPrice);
                L2REverydayStockDto l2REverydayStockDto=stockMap.get(DateUtil.format(rmPrice.getDate(),DateUtil.webFormat));
                if(l2REverydayStockDto==null){
                    isBookableFlag=false;
                }else {
                    Integer num=0;
                    if(DefaultValue.F.equals(l2REverydayStockDto.getIsClosed())){
                        num=l2REverydayStockDto.getSaleNum();
                    }
                    if(num>0){
                        isFullFlag=false;
                    }
                }
                l2REverydayPriceAndStockDto.setL2REverydayStockDto(l2REverydayStockDto);
                l2REverydayPriceAndStockDto.setRsvDate(rmPrice.getDate());
                l2REverydayPriceAndStockDto.datetimeToString();
                l2REverydayPriceAndStockDtos.add(l2REverydayPriceAndStockDto);
            }
        }

        bookStockDto.setLhotelGroupCode(mcd.getLhotelGroupCode());
        bookStockDto.setLhotelCode(mcd.getLhotelCode());
        bookStockDto.setRmtype(mcd.getRmtype());
        bookStockDto.setL2REverydayPriceAndStockDtoList(l2REverydayPriceAndStockDtos);
        if(minSaleNum!=9999){
            bookStockDto.setMinSaleNum(minSaleNum);
            if(minSaleNum<=0){
                isBookableFlag=false;
            }
        }else {
            isBookableFlag=false;
        }
        if(minSaleNum<bookStockInsideParamDto.getRmNum()){
            isBookableFlag=false;
        }
        if(l2REverydayPriceAndStockDtos.size()<1){
            isBookableFlag=false;
        }
        if(isBookableFlag){
            bookStockDto.setIsBookable(DefaultValue.T);
        }
        if(isFullFlag){
            bookStockDto.setIsFull(DefaultValue.T);
        }
        bookStockDto.setTotalPriceCost(totalPriceCost);
        bookStockDto.setTotalPriceSale(totalPriceSale);
        bookStockDto.setTotalPricePms(totalPricePms);

        if(StringUtil.isNotBlank(bookStockInsideParamDto.getIsUsePoint())&&DefaultValue.T.equals(bookStockInsideParamDto.getIsUsePoint())&&StringUtil.isNotBlank(pointRule)){
            if(!DefaultValue.NONE.equals(pointRule)&&DefaultValue.T.equals(memberSession.getIsMember())){
                PointBaseParamDto pointBaseParamDto=new PointBaseParamDto();
                pointBaseParamDto.setLhotelCode(bookStockInsideParamDto.getLhotelCode());
                pointBaseParamDto.setL2rMemberNo(memberSession.getMemberNo());
                pointBaseParamDto.setTotalPriceSale(totalPriceSale);
                pointBaseParamDto.setPointRuleCode(pointRule);
                pointBaseParamDto.setArrDateStr(bookStockInsideParamDto.getCheckInDatetime());
                pointBaseParamDto.setDepDateStr(bookStockInsideParamDto.getCheckOutDatetime());
                PointCheckDto pointCheckDto = pointFeignService.checkPointRule(pointBaseParamDto.paramToMap()).getResultInfo();
                bookStockDto.setCanUsePoint(pointCheckDto.getCanUsePoint());
                bookStockDto.setUsePoint(pointCheckDto.getUsePoint());
                bookStockDto.setPointToMoney(pointCheckDto.getPointToMoney());
                bookStockDto.setPointPayTaCode(pointCheckDto.getPointPayTaCode());
            }
        }
        //bookStockDto.setTotalPrice(new BigDecimal(0.01));
        bookStockDto.setComm(commission.getComm());
        bookStockDto.setResType(resType);
        bookStockDto.setPmsRatecode(pmsRatecode);
        bookStockDto.setCommCode(commission.getCommCode());
        bookStockDto.setIsToPms(mc.getIsToPms());
        bookStockDto.setMcName(mc.getMcName());
        bookStockDto.setMcNameEn(mc.getMcNameEn());
        bookStockDto.setMcdName(mcd.getMcdName());
        bookStockDto.setMcdNameEn(mcd.getMcdNameEn());
        bookStockDto.setRmtypeName(mcd.getRmtypeName());
        bookStockDto.setRmtypeNameEn(mcd.getRmtypeNameEn());
        bookStockDto.setHotelName(HotelUtil.getRedisHotelName(bookStockInsideParamDto.getLhotelCode()));
        bookStockDto.setHotelNameEn(HotelUtil.getRedisHotelNameEn(bookStockInsideParamDto.getLhotelCode()));
        return bookStockDto;
    }

    /**
     * 下单/取消订单变更房量
     * @param reservationParamDto
     * @throws Exception
     */
    @Override
    public void changeMarketingStock(ReservationParamDto reservationParamDto)throws Exception{
        if(ReservationConstant.OPERTYPE.CANCEL.equals(reservationParamDto.getOperType())||
                ReservationConstant.OPERTYPE.REVERT.equals(reservationParamDto.getOperType())){
            reservationParamDto.getReservationBase().setRoomNum(-reservationParamDto.getReservationBase().getRoomNum());
        }
        Date arr = DateUtil.parseDateNoTime(reservationParamDto.getReservationBase().getArr());
        Date dep = DateUtil.parseDateNoTime(reservationParamDto.getReservationBase().getDep());
        String lhotelGroupCode=reservationParamDto.getReservationBase().getLhotelGroupCode();
        String lhotelCode=reservationParamDto.getReservationBase().getLhotelCode();
        String mcdCode=reservationParamDto.getReservationBase().getMcdCode();
        String rmtype=reservationParamDto.getReservationBase().getRmtype();
        Integer rmNum=reservationParamDto.getReservationBase().getRoomNum();
        L2RCondition l2RCondition = new L2RCondition();
        l2RCondition.setAndConditions(new ConditionDetail[]{
                new ConditionDetail(BaseEntity.BaseEntity_.lhotelGroupCode.toString(), CriteriaUtil.Operator.EQ, reservationParamDto.getReservationBase().getLhotelGroupCode()),
                new ConditionDetail(BaseEntity.BaseEntity_.lhotelCode.toString(), CriteriaUtil.Operator.EQ, reservationParamDto.getReservationBase().getLhotelCode()),
                new ConditionDetail(MarketingCampaignsStock.MarketingCampaignsStock_.mcdCode.toString(), CriteriaUtil.Operator.EQ, mcdCode),
                new ConditionDetail(MarketingCampaignsStock.MarketingCampaignsStock_.rsvDate.toString(), CriteriaUtil.Operator.GTE, DateUtil.parseDateNoTime(reservationParamDto.getReservationBase().getArr())),
                new ConditionDetail(MarketingCampaignsStock.MarketingCampaignsStock_.rsvDate.toString(), CriteriaUtil.Operator.LT, DateUtil.parseDateNoTime(reservationParamDto.getReservationBase().getDep()))
        });

        ReservationNmsStaInsideParamDto reservationNmsStaParam = new ReservationNmsStaInsideParamDto();
        reservationNmsStaParam.setOptId(reservationParamDto.getOptId());
        reservationNmsStaParam.setLhotelGroupCode(lhotelGroupCode);
        reservationNmsStaParam.setLhotelCode(lhotelCode);
        reservationNmsStaParam.setL2RNo(reservationParamDto.getReservationBase().getL2RNo());
        reservationNmsStaParam.setOperType(reservationParamDto.getOperType());
        reservationNmsStaParam.setItem(BaseConstant.ServiceCategoryConstant.OPTIMUS);
        try {
            QueryResult<MarketingCampaignsStockSold> stockSoldResult = commonService.findAllByCondition(MarketingCampaignsStockSold.class, l2RCondition);
            List<MarketingCampaignsStockSold> stockSoldList = stockSoldResult.getResultlist();

            //TODO 可能多一天
            List<Date> dates = DateUtil.dateBewteen(arr, DateUtil.addDays(dep,-1L));
            List<MarketingCampaignsStockSold> mcssList=new ArrayList<>();
            for(Date date:dates){
                MarketingCampaignsStockSold mcss=new MarketingCampaignsStockSold(lhotelGroupCode,lhotelCode,
                        mcdCode,rmtype,date,DateUtil.getDateWeek(date),rmNum,rmNum);
                if (stockSoldList != null) {
                    for (MarketingCampaignsStockSold stockSold : stockSoldList) {
                        if(DateUtil.format(date,DateUtil.webFormat).equals(DateUtil.format(stockSold.getRsvDate(),DateUtil.webFormat))){
                            mcss=stockSold;
                            mcss.setSoldNum(stockSold.getSoldNum() + reservationParamDto.getReservationBase().getRoomNum());
                            mcss.setCurrentSoldNum(stockSold.getCurrentSoldNum() + reservationParamDto.getReservationBase().getRoomNum());
                        }
                    }
                }
                mcssList.add(mcss);
            }
            commonService.saveOrMergeList(mcssList);
            reservationNmsStaParam.setOperSta(DefaultValue.T);
            mnsUtil.putMessageToQueue(JetfireMnsConstant.QUEUE_ORDER_STA, JacksonUtil.beanToJson(reservationNmsStaParam));
        }catch (Exception e) {
            reservationNmsStaParam.setOperSta(DefaultValue.F);
            mnsUtil.putMessageToQueue(JetfireMnsConstant.QUEUE_ORDER_STA, JacksonUtil.beanToJson(reservationNmsStaParam));
            throw e;
        }
    }

    @Override
    public QueryResult<MarketingHotelDto> listMarketingHotels(MarketingManagerParamDto marketingManagerParamDto)throws Exception{
        HotelBaseInfoInsideParamDto hotelBaseInfoInsideParamDto =new HotelBaseInfoInsideParamDto();
        QueryResult<HotelBaseInfoDto> hotelBaseInfoDtoResult = hotelBaseInfoFeignService.hotelBaseInfoList(hotelBaseInfoInsideParamDto.paramToMap()).getQueryResult();
        List<HotelBaseInfoDto> hotelBaseInfoList = hotelBaseInfoDtoResult.getResultlist();
        MarketingCampaignsHotel querymch=new MarketingCampaignsHotel();
        querymch.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        querymch.setMcCode(marketingManagerParamDto.getMcCode());
        QueryResult<MarketingCampaignsHotel> mcHotelResult = commonService.findAllEQ(MarketingCampaignsHotel.class, querymch);
        List<MarketingCampaignsHotel> mcHotelList = mcHotelResult.getResultlist();
        List<MarketingHotelDto> marketingHotelList=new ArrayList<>();
        if(hotelBaseInfoList!=null){
            if(mcHotelList!=null){
                for (HotelBaseInfoDto hotelBaseInfo:hotelBaseInfoList){
                    MarketingHotelDto mHotel=ClassConverUtil.copyProperties(hotelBaseInfo,MarketingHotelDto.class);
                    mHotel.setIsHalt(DefaultValue.T);
                    mHotel.setId(null);
                    mHotel.setMcCode(marketingManagerParamDto.getMcCode());
                    for(MarketingCampaignsHotel mcHotel:mcHotelList){
                        if(hotelBaseInfo.getLhotelCode().equals(mcHotel.getLhotelCode())){
                            mHotel.setId(mcHotel.getId());
                            mHotel.setIsHalt(mcHotel.getIsHalt());
                            mHotel.setIsNew(DefaultValue.F);
                        }
                    }
                    marketingHotelList.add(mHotel);
                }
            }
        }
        QueryResult<MarketingHotelDto> marketingHotelResult=new QueryResult<>();
        marketingHotelResult.setResultlist(marketingHotelList);
        marketingHotelResult.setCurrentPage(hotelBaseInfoDtoResult.getCurrentPage());
        marketingHotelResult.setTotalrecord(hotelBaseInfoDtoResult.getTotalrecord());
        return marketingHotelResult;
    }

    /**
     * 变更选择酒店
     * @param marketingManagerParamDto
     * @throws Exception
     */
    @Override
    public List<MarketingHotelDto> updateMarketingHotels(MarketingManagerParamDto marketingManagerParamDto)throws Exception{
        List<MarketingHotelDto> mHotels = marketingManagerParamDto.getMarketingHotels();
        MarketingCampaignsChannel querymcc=new MarketingCampaignsChannel();
        querymcc.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        querymcc.setMcCode(marketingManagerParamDto.getMcCode());
        querymcc.setIsHalt(DefaultValue.F);
        QueryResult<MarketingCampaignsChannel> mccResult = commonService.findAllEQ(MarketingCampaignsChannel.class, querymcc);
        List<MarketingCampaignsChannel> mccList = mccResult.getResultlist();

        MarketingCampaigns querymc=new MarketingCampaigns();
        querymc.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        querymc.setMcCode(marketingManagerParamDto.getMcCode());
        MarketingCampaigns mc= commonService.findOneEQ(MarketingCampaigns.class, querymc);


        MarketingCampaignsRmtype querymcr=new MarketingCampaignsRmtype();
        querymcr.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
        querymcr.setMcCode(marketingManagerParamDto.getMcCode());
        QueryResult<MarketingCampaignsRmtype> mcrResult = commonService.findAllEQ(MarketingCampaignsRmtype.class, querymcc);
        List<MarketingCampaignsRmtype> mcrList = mcrResult.getResultlist();

        MarketingBaseParamDto marketingParam;
        List<MarketingCampaignsHotel> marketingCampaignsHotels =null;
        List<RateplanHotelManagerParamDto> rateplanHotelManagerParamDtos =new ArrayList<>();
        List<MarketingBaseParamDto> marketingBaseParamDtos=new ArrayList<>();
        if(mHotels!=null){
            for(MarketingHotelDto mHotel:mHotels){
                RateplanHotelManagerParamDto rateplanHotelManagerParamDto =new RateplanHotelManagerParamDto();
                rateplanHotelManagerParamDto.setLhotelCode(mHotel.getLhotelCode());
                rateplanHotelManagerParamDto.setMarketingPbChannels(ClassConverUtil.copyPropertiesListToDtoList(mccList,MarketingPbChannelDto.class,false));
                rateplanHotelManagerParamDto.setMarketingHotel(mHotel);
                rateplanHotelManagerParamDtos.add(rateplanHotelManagerParamDto);


                if (DefaultValue.T.equals(mHotel.getIsNew())) {
                    marketingParam=new MarketingBaseParamDto();
                    marketingParam.setLhotelGroupCode(marketingManagerParamDto.getLhotelGroupCode());
                    marketingParam.setLhotelCode(mHotel.getLhotelCode());
                    marketingParam.setMcCode(mc.getMcCode());
                    marketingParam.setMcName(mc.getMcName());
                    marketingParam.setMcNameEn(mc.getMcNameEn());
                    marketingParam.setMarketingRmtypes(ClassConverUtil.copyPropertiesList(mcrList,MarketingRmtypeDto.class));
                    marketingParam.setOptType(DefaultValue.POST);
                    marketingBaseParamDtos.add(marketingParam);
                }
            }
            BatchUtil.beginBatchTask(OptimusMnsConstant.QUEUE_RATEPLANHOTEL,
                    OptimusTaskNameConstant.SAVE_OR_UPDATE_RATEPLAN_HOTEL,
                    rateplanHotelManagerParamDtos);

            BatchUtil.beginBatchTask(OptimusMnsConstant.QUEUE_MARKETINGDETAIL,
                    OptimusTaskNameConstant.SAVE_MARKETING_DETAIL,
                    marketingBaseParamDtos);
            marketingCampaignsHotels = ClassConverUtil.copyPropertiesList(mHotels, MarketingCampaignsHotel.class);
            commonService.saveOrUpdateList(marketingCampaignsHotels);
        }
        return ClassConverUtil.copyPropertiesListToDtoList(marketingCampaignsHotels,MarketingHotelDto.class,false);
    }

    @Override
    public void updateMarketingHotelsForTask(MarketingManagerParamDto marketingManagerParamDto)throws Exception{
        this.updateMarketingHotels(marketingManagerParamDto);
        BatchUtil.doBatchTaskDone(marketingManagerParamDto.getTaskMainId(),
                marketingManagerParamDto.getTaskId(),
                marketingManagerParamDto.getIsBatch());
    }

    @Override
    public List<L2REverydayPriceAndStockDto> getMarketingDetailDataList(MarketingBaseParamDto marketingBaseParamDto)throws Exception{
        String lhotelGroupCode=marketingBaseParamDto.getLhotelGroupCode();
        String lhotelCode=marketingBaseParamDto.getLhotelCode();
        String mcdCode=marketingBaseParamDto.getMcdCode();
        String startDatetime=marketingBaseParamDto.getStartDatetime();
        String endDatetime=marketingBaseParamDto.getEndDatetime();

        MarketingCampaignsDetail queryMCD=new MarketingCampaignsDetail();
        queryMCD.setLhotelGroupCode(lhotelGroupCode);
        queryMCD.setLhotelCode(lhotelCode);
        queryMCD.setMcdCode(mcdCode);
        MarketingCampaignsDetail mcd = commonService.findOneEQ(MarketingCampaignsDetail.class, queryMCD);

        RoomtypeBaseParamDto roomtypeBaseParamDto=new RoomtypeBaseParamDto();
        roomtypeBaseParamDto.setLhotelCode(lhotelCode);
        roomtypeBaseParamDto.setRmtype(mcd.getRmtype());
        L2RRoomtypeDto roomType = roomtypeFeignService.roomTypeDto(roomtypeBaseParamDto.paramToMap()).getResultInfo();

        if(mcd!=null){
            String mcCode=mcd.getMcCode();
            MarketingCampaigns queryMC=new MarketingCampaigns();
            queryMC.setLhotelGroupCode(lhotelGroupCode);
            queryMC.setMcCode(mcCode);
            MarketingCampaigns mc = commonService.findOneEQ(MarketingCampaigns.class, queryMC);
            //查询价格池代码
            MarketingCampaignsPrice queryMCP=new MarketingCampaignsPrice();
            queryMCP.setLhotelGroupCode(lhotelGroupCode);
            queryMCP.setMcCode(mcCode);
            String memberLevel=marketingBaseParamDto.getMemberLevel();
            if(StringUtil.isBlank(memberLevel)){
                memberLevel=MemberConstant.MEMBER_LEVEL.L0;
            }
            queryMCP.setMemberLevel(memberLevel);
            queryMCP.setPbChannel(marketingBaseParamDto.getPbChannel());
            MarketingCampaignsPrice mcp = commonService.findOneEQ(MarketingCampaignsPrice.class, queryMCP);
            //查询价格池
            PricePool queryPP=new PricePool();
            queryPP.setLhotelGroupCode(lhotelGroupCode);
            queryPP.setPoolCode(mcp.getPoolCode());
            PricePool pp=commonService.findOneEQ(PricePool.class,queryPP);
            //查询基价
            QueryResult<PriceStaticMapper> priceStaticResult = marketingService.getRmtypeStaticPrice(lhotelGroupCode, lhotelCode,mc.getPriceCode(), mcd.getRmtype(), startDatetime, endDatetime);
            List<PriceStaticMapper> priceStatics=priceStaticResult.getResultlist();

            PmsRoomAvailInsideParamDto roomAvailParamDto=new PmsRoomAvailInsideParamDto();
            roomAvailParamDto.setLhotelGroupCode(mcd.getLhotelGroupCode());
            roomAvailParamDto.setLhotelCode(mcd.getLhotelCode());
            roomAvailParamDto.setL2RRmtypes(mcd.getRmtype());
            roomAvailParamDto.setArrtime(startDatetime);
            roomAvailParamDto.setDeptime(endDatetime);
            QueryResult<PmsRmtypeAvailDto> roomAvailResult = pmsAvailFeignService.getRoomAvail(roomAvailParamDto.paramToMap()).getQueryResult();
            List<PmsRmtypeAvailDto> roomAvailList = roomAvailResult.getResultlist();
            L2RCondition stockConfition=new L2RCondition();
            stockConfition.setAndConditions(new ConditionDetail[]{
                    new ConditionDetail(BaseEntity.BaseEntity_.lhotelGroupCode.toString(), CriteriaUtil.Operator.EQ,mcd.getLhotelGroupCode()),
                    new ConditionDetail(BaseEntity.BaseEntity_.lhotelCode.toString(), CriteriaUtil.Operator.EQ,mcd.getLhotelCode()),
                    new ConditionDetail(MarketingCampaignsStock.MarketingCampaignsStock_.mcdCode.toString(), CriteriaUtil.Operator.EQ,mcd.getMcdCode()),
                    new ConditionDetail(MarketingCampaignsStock.MarketingCampaignsStock_.rsvDate.toString(), CriteriaUtil.Operator.GTE, marketingBaseParamDto.getStartDate()),
                    new ConditionDetail(MarketingCampaignsStock.MarketingCampaignsStock_.rsvDate.toString(), CriteriaUtil.Operator.LT, marketingBaseParamDto.getEndDate())
            });
            QueryResult<MarketingCampaignsStock> marketingStockResult = commonService.findAllByCondition(MarketingCampaignsStock.class, stockConfition);
            List<MarketingCampaignsStock> marketingStockList = marketingStockResult.getResultlist();
            QueryResult<MarketingCampaignsStockSold> marketingStockSoldResult = commonService.findAllByCondition(MarketingCampaignsStockSold.class, stockConfition);
            List<MarketingCampaignsStockSold> marketingStockSoldList = marketingStockSoldResult.getResultlist();

            HashMap<String,MarketingCampaignsStock> mcsMap=new HashMap<>();
            HashMap<String,MarketingCampaignsStockSold> mcsdMap=new HashMap<>();

            if(marketingStockList!=null){
                for(MarketingCampaignsStock marketingStock:marketingStockList){
                    if(DefaultValue.T.equals(mcd.getIsHalt())||DefaultValue.T.equals(roomType.getIsHalt())){
                        marketingStock.setIsClosed(DefaultValue.T);
                    }
                    mcsMap.put(DateUtil.format(marketingStock.getRsvDate(),DateUtil.webFormat),marketingStock);
                }
            }
            if(marketingStockSoldList!=null){
                for(MarketingCampaignsStockSold marketingStockSold:marketingStockSoldList){
                    mcsdMap.put(DateUtil.format(marketingStockSold.getRsvDate(),DateUtil.webFormat),marketingStockSold);
                }
            }
            List<L2REverydayPriceAndStockDto> l2REverydayPriceAndStockDtos=new ArrayList<>();
            Map<String,L2REverydayStockDto> stockMap=new HashMap<>();
            if(roomAvailList!=null){
                int i=0;
                for(PmsRmtypeAvailDto roomAvail:roomAvailList){
                    i++;
                    String rsvDate=DateUtil.format(roomAvail.getRsvDate(),DateUtil.webFormat);
                    MarketingCampaignsStock mcs = mcsMap.get(rsvDate);
                    MarketingCampaignsStockSold mcsd = mcsdMap.get(rsvDate);
                    Integer saleNum = marketingService.getSaleNum(mc.getUseRealAvail(), mc.getUseSetNum(), mcd.getSetNum(), mcs, mcsd, roomAvail);

                    L2REverydayStockDto l2REverydayStockDto=new L2REverydayStockDto();
                    l2REverydayStockDto.setSaleNum(saleNum);
                    String isClosed=DefaultValue.F;
                    if(mcsMap.get(rsvDate)!=null){
                        isClosed=mcsMap.get(rsvDate).getIsClosed();
                    }
                    l2REverydayStockDto.setIsClosed(isClosed);
                    stockMap.put(rsvDate,l2REverydayStockDto);
                }
            }

            if(priceStatics!=null){
                for(PriceStaticMapper rmPrice:priceStatics){
                    L2REverydayPriceAndStockDto l2REverydayPriceAndStockDto=new L2REverydayPriceAndStockDto();
                    L2REverydayPriceDto l2reverydayPriceDto=new L2REverydayPriceDto();
                    BigDecimal costPrice= PricePoolUtil.getPriceResult(rmPrice.getPrice(),pp.getCarryType(),pp.getMultiplyValueCost(),pp.getAddValueCost());
                    BigDecimal salePrice= PricePoolUtil.getPriceResult(rmPrice.getPrice(),pp.getCarryType(),pp.getMultiplyValueSale(),pp.getAddValueSale());
                    l2reverydayPriceDto.setCostPrice(costPrice);
                    l2reverydayPriceDto.setCurrentPrice(salePrice);

                    l2REverydayPriceAndStockDto.setL2REverydayPriceDto(l2reverydayPriceDto);
                    l2REverydayPriceAndStockDto.setL2REverydayStockDto(stockMap.get(DateUtil.format(rmPrice.getDate(),DateUtil.webFormat)));
                    l2REverydayPriceAndStockDto.setRsvDate(rmPrice.getDate());
                    l2REverydayPriceAndStockDto.datetimeToString();
                    l2REverydayPriceAndStockDtos.add(l2REverydayPriceAndStockDto);
                }
            }
            return l2REverydayPriceAndStockDtos;
        }else{
            throw new OptimusException(OptimusSysExceptionEnum.MCD_IS_NOT_EXIT);
        }
    }

    /**
     * 可定检查已售罄后自动关房
     * @param marketingStockBaseParamDto
     * @throws Exception
     */
    @Override
    public void saveOrUpdateMarketingStockToClosed(MarketingStockBaseParamDto marketingStockBaseParamDto)throws Exception{
        if(marketingStockBaseParamDto.getMarketingStockDtoList()!=null&&marketingStockBaseParamDto.getMarketingStockDtoList().size()>0){
            String mcdCode=marketingStockBaseParamDto.getMcdCode();
            String lhotelCode=marketingStockBaseParamDto.getLhotelCode();
            String lhotelGroupCode=marketingStockBaseParamDto.getLhotelGroupCode();
            List<Date> dates=new ArrayList<>();
            for(MarketingStockDto stock:marketingStockBaseParamDto.getMarketingStockDtoList()){
                dates.add(stock.getRsvDate());
            }
            L2RCondition l2RCondition=new L2RCondition();
            l2RCondition.setAndConditions(new ConditionDetail[]{
                    new ConditionDetail(BaseEntity.BaseEntity_.lhotelGroupCode.toString(), CriteriaUtil.Operator.EQ,lhotelGroupCode),
                    new ConditionDetail(BaseEntity.BaseEntity_.lhotelCode.toString(), CriteriaUtil.Operator.EQ,lhotelCode),
                    new ConditionDetail(MarketingCampaignsStock.MarketingCampaignsStock_.mcdCode.toString(), CriteriaUtil.Operator.EQ,mcdCode),
                    new ConditionDetail(MarketingCampaignsStock.MarketingCampaignsStock_.rsvDate.toString(), CriteriaUtil.Operator.IN,dates),
            });
            QueryResult<MarketingCampaignsStock> oldMarketingStockResult = commonService.findAllByCondition(MarketingCampaignsStock.class, l2RCondition);
            Iterator<MarketingStockDto> stockIterator = marketingStockBaseParamDto.getMarketingStockDtoList().iterator();
            while (stockIterator.hasNext()){
                MarketingStockDto marketingStockDto= stockIterator.next();
                if(oldMarketingStockResult.getResultlist()!=null){
                    for(MarketingCampaignsStock oldStock:oldMarketingStockResult.getResultlist()){
                        if(oldStock.getMcdCode().equals(marketingStockDto.getMcdCode())
                                &&marketingStockDto.getRsvDateStr().equals(DateUtil.getWebDateString(oldStock.getRsvDate()))){
                            oldStock.setIsClosed(DefaultValue.T);
                            stockIterator.remove();
                        }
                    }
                }
            }
            if(oldMarketingStockResult.getResultlist()!=null) {
                commonService.mergeList(oldMarketingStockResult.getResultlist());
            }
            commonService.saveList(ClassConverUtil.copyPropertiesList(marketingStockBaseParamDto.getMarketingStockDtoList(),MarketingCampaignsStock.class));
        }
    }

    private String getComposeMcName(MarketingCampaigns mc){
        return mc.getMcName()+"("+mc.getMcCode()+")";
    }

}
